package com.tz.test.listener;

import com.rabbitmq.client.Channel;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @author zhangky
 * @since 2020/5/7
 */
@Component
@Scope("prototype")
public class BsDataSyncListener implements ChannelAwareMessageListener {

    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
        byte[] body = message.getBody();
        String s = new String(body);
        if(!StringUtils.isEmpty(s)) {
            System.out.println("接受到的消息" + s);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        }
    }
}
